var buildEditApp = buildEditApp || {};
buildEditApp.model = buildEditApp.model || {};
buildEditApp.view = buildEditApp.view || {};

$(function () {

    //model
    buildEditApp.model.buildModel = Backbone.Model.extend({
        url: window.ctx + "/rest/money/get",
        defaults: {
            id:'',
            buildName:'',
            roomNum:'',
            payInTime:'',
            payBeginTime:'',
            payEndTime:'',
            payMoney:'',
            createTime:'',
        }
    });
    buildEditApp.view.executeView = Backbone.View.extend({
        el: "#formDiv",

        model: new buildEditApp.model.buildModel(),

        template: _.template($("#moneyTem").html()),

        //绑定元素
        events: {
            "click #saveBtn": "save",
            "click #backBtn": "back"
        },

        initialize: function () {
            var context = this;
            this.model.fetch({
                data: {
                    id: $("form").find("[name=id]").val()
                },
                success: function () {
                    context.render()
                },
                error: function () {
                    hintDialog("获取业主信息失败！");
                }
            });
        },
        render: function () {
            $(this.el).find("form").append(this.template(this.model.toJSON()));
            $(":text:eq(0)").focus();
        },
        save: function () {
            var context = this;
            $(context.el).find("form").submit();
        },
        back: function () {
            location.href = window.ctx + "/build/list";
        }
    });
    new buildEditApp.view.executeView();
});